package com.adnauseum;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * Created by IntelliJ IDEA.
 * User: gerken
 * Date: 1/10/12
 * Time: 7:42 PM
 * To change this template use File | Settings | File Templates.
 */
public class MainMenu extends Activity {
    private Button scoreScreen;
    private Button poison;
    private Button settings;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initialize();
    }

    private void initialize() {
        RelativeLayout relativeLayout = new RelativeLayout(getApplicationContext());
        relativeLayout.setId(relativeLayout.hashCode());
        relativeLayout.setBackgroundColor(getResources().getColor(R.color.dark_gray));
        RelativeLayout.LayoutParams lp;

        int iconWidth = getWindow().getWindowManager().getDefaultDisplay().getWidth() / 2;

        RelativeLayout healthHolderr = new RelativeLayout(getApplicationContext());
        healthHolderr.setId(healthHolderr.hashCode());
        healthHolderr.setPadding(0,30,0,0);
        scoreScreen = new Button(getApplicationContext());
        scoreScreen.setId(scoreScreen.hashCode());
        scoreScreen.setBackgroundDrawable(getResources().getDrawable(R.drawable.health));
        scoreScreen.setOnClickListener(getButtonListener());
        lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        healthHolderr.addView(scoreScreen, lp);
        TextView view = new TextView(getApplicationContext());
        view.setText("New Game");
        lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        lp.addRule(RelativeLayout.BELOW, scoreScreen.getId());
        healthHolderr.addView(view, lp);
        lp = new RelativeLayout.LayoutParams(iconWidth, RelativeLayout.LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.ALIGN_LEFT);
        lp.addRule(RelativeLayout.ALIGN_TOP, relativeLayout.getId());
        relativeLayout.addView(healthHolderr, lp);

        RelativeLayout settingsHolder = new RelativeLayout(getApplicationContext());
        settingsHolder.setId(settingsHolder.hashCode());
        settingsHolder.setPadding(0,30,0,0);
        settings = new Button(getApplicationContext());
        settings.setId(settings.hashCode());
        settings.setBackgroundDrawable(getResources().getDrawable(R.drawable.bolt));
        settings.setOnClickListener(getButtonListener());
        lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        settingsHolder.addView(settings, lp);
        view = new TextView(getApplicationContext());
        view.setText("Settings");
        lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        lp.addRule(RelativeLayout.BELOW, settings.getId());
        settingsHolder.addView(view, lp);
        lp = new RelativeLayout.LayoutParams(iconWidth, RelativeLayout.LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.ALIGN_LEFT);
        lp.addRule(RelativeLayout.BELOW, healthHolderr.getId());
        relativeLayout.addView(settingsHolder, lp);

        RelativeLayout poisonHolder = new RelativeLayout(getApplicationContext());
        poisonHolder.setId(poisonHolder.hashCode());
        poisonHolder.setPadding(0,30,0,0);
        poison = new Button(getApplicationContext());
        poison.setId(poison.hashCode());
        poison.setBackgroundDrawable(getResources().getDrawable(R.drawable.poison));
        poison.setOnClickListener(getButtonListener());
        lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        poisonHolder.addView(poison, lp);
        view = new TextView(getApplicationContext());
        view.setText("Poison Settings");
        lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        lp.addRule(RelativeLayout.BELOW, poison.getId());
        poisonHolder.addView(view, lp);
        lp = new RelativeLayout.LayoutParams(iconWidth, RelativeLayout.LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.RIGHT_OF, healthHolderr.getId());
        lp.addRule(RelativeLayout.ALIGN_TOP, relativeLayout.getId());
        relativeLayout.addView(poisonHolder, lp);

        View bottom = new View(getApplicationContext());
        bottom.setBackgroundColor(getResources().getColor(R.color.dark_red));
        lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, 20);
        lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, relativeLayout.getId());
        relativeLayout.addView(bottom, lp);

        bottom = new View(getApplicationContext());
        bottom.setBackgroundColor(getResources().getColor(R.color.dark_red));
        lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, 20);
        lp.addRule(RelativeLayout.ALIGN_TOP, relativeLayout.getId());
        relativeLayout.addView(bottom, lp);
        
        setContentView(relativeLayout);
    }

    private View.OnClickListener getButtonListener(){
        return new View.OnClickListener() {
            public void onClick(View v) {
                if (v.equals(scoreScreen)) {
                    //todo: change the following to popup a menu so the user can select an appropriate game mode mode and number
                    //of players
                    Intent intent = new Intent();
                    intent.setClass(getApplicationContext(), ScoreScreen.class);
                    startActivity(intent);
                } else if (v.equals(settings)) {
                    //todo; implement settings menu activity.
                } else if (v.equals(poison)) {
                    //todo; remove poison as it is a place holder. Add other required main menu options
                }
            }
        };
    }



}